/**
 * Created by baiguiren on 1/16/17.
 */

const async = require('async');

// async.each([1, 2, 3], function (num) {
//     console.log(num);
// });

const arr1 = [
    {
        name: 'awk'
    },
    {
        name: 'ruby'
    }
];
async.map(arr1, function (item, callback) {
    process.nextTick(function () {
        callback(null, item.name + 's')
    })
}, function (err, results) {
    console.log(results);
});

const arr = [{name:'Jack', delay:200}, {name:'Mike', delay: 100}, {name:'Freewind', delay:300}, {name:'Test', delay: 50}];

async.map(arr, function (item, callback) {
    console.log('enter ' + item.name);
    setTimeout(function () {
        console.log('finish ' + item.name);
        callback(null, item.name + '@@@');
    }, item.delay);
}, function (err, results) {
    console.log(results);
});

async.mapSeries(arr, function (item, callback) {
    console.log('enter ' + item.name);
    setTimeout(function () {
        console.log('finish ' + item.name);
        callback(null, item.name + '@@');
    }, item.delay);
}, function (err, results) {
    console.log(results);
});

async.mapLimit(arr, 2, function (item, callback) {
    console.log('enter ' + item.name);
    setTimeout(function () {
        console.log('finish @' + item.name);
        callback(null, item.name + '&&');
    }, item.delay);
}, function (err, results) {
    console.log(results);
});